package com.qfjy.huzewang;

import java.util.ArrayList;
import java.util.List;

public class Server implements Observerable {
    private List<Observer> list;
    private String information;

    public Server() {
        list = new ArrayList<>();
    }

    @Override
    public void login(Observer user) {
        list.add(user);
    }

    @Override
    public void information() {
        for(int i = 0; i < list.size(); i++) {
            Observer observer = list.get(i);
            observer.read(this.information);
        }
    }

    @Override
    public void logout(Observer user) {
        list.remove(user);
    }

    public void setInformation(String s) {
        this.information = s;
        //消息更新，通知所有观察者
        information();
    }
}
